package com.kaigejava.singleton;

/**
 * Created by kaigejava on 2019/8/21.
 * Double CheckLock实现单例：DCL也就是双重锁判断机制（由于JVM底层模型原因，偶尔会出问题，不建议使用）：
 */
public class DoubleCheckLockSingleton {
    private static  DoubleCheckLockSingleton doubleCheckLockSingleton = null;

    private DoubleCheckLockSingleton(){}


    /**
     * 双重校验+锁模式
     * @return
     */
    public static DoubleCheckLockSingleton getInstance(){
        if(null == doubleCheckLockSingleton){
            synchronized (DoubleCheckLockSingleton.class){
                if(null == doubleCheckLockSingleton){
                    doubleCheckLockSingleton = new DoubleCheckLockSingleton();
                }
            }
        }
        return doubleCheckLockSingleton;
    }
}
